package Ventanas;

import Descriptores.DescriptorCargo;
import Descriptores.DescriptorFichero;
import Descriptores.DescriptorPersonaje;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Daniel
 */
public class VentanaCrearPj extends javax.swing.JFrame {

    private GUIManager manejador;
    private DescriptorPersonaje personaje;
    private ArrayList<DescriptorFichero> fichCargo;
    private estados estado;
    private ArrayList<DescriptorCargo> cargos;
    private ArrayList<String> alias;

    /** Creates new form VentanaCrearPj */
    public VentanaCrearPj(GUIManager m) {
        estado = null;
        manejador = m;
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(d.width / 4, 20);
        initComponents();
        this.setTitle("Crear Personaje");
        this.setDefaultCloseOperation(0);
        personaje = new DescriptorPersonaje();
        fichCargo = new ArrayList<DescriptorFichero>();
        cargos = new ArrayList<DescriptorCargo>();
        alias = new ArrayList<String>();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        textoNomYApe = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        AnoNac = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        MesNac = new javax.swing.JTextField();
        DiaNac = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        AnoDef = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        MesDef = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        DiaDef = new javax.swing.JTextField();
        panelCargo = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        AnoIni = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        MesIni = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        textCargo = new javax.swing.JTextField();
        AnoFin = new javax.swing.JTextField();
        MesFin = new javax.swing.JTextField();
        DiaIni = new javax.swing.JTextField();
        DiaFin = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textDescCargo = new javax.swing.JTextArea();
        botonCargo = new javax.swing.JButton();
        panelFicheros = new javax.swing.JPanel();
        labelTitulo5 = new javax.swing.JLabel();
        textFormato = new javax.swing.JTextField();
        labelTitulo6 = new javax.swing.JLabel();
        textURIFich = new javax.swing.JTextField();
        botonAddFich = new javax.swing.JButton();
        labelTitulo7 = new javax.swing.JLabel();
        textNomFich = new javax.swing.JTextField();
        jScrollPane5 = new javax.swing.JScrollPane();
        tablaFicheros = new javax.swing.JTable();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jLabel19 = new javax.swing.JLabel();
        jButton8 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        textAlias = new javax.swing.JTextField();
        botonAlias = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        botonAceptar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaAlias = new javax.swing.JTable();
        jLabel23 = new javax.swing.JLabel();
        textoLugarNac = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        textoLugarDef = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        textBiografia = new javax.swing.JTextArea();
        jScrollPane4 = new javax.swing.JScrollPane();
        tablaCargos = new javax.swing.JTable();
        jLabel26 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setText("Nombre y Apellidos:");

        textoNomYApe.setText("Arnold Swarchseneger");

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setText("Fecha de nacimiento:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel3.setText("Año");

        AnoNac.setText("1951");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel4.setText("Mes");

        MesNac.setText("04");

        DiaNac.setText("23");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel5.setText("Dia");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel6.setText("Fecha de defuncion:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel7.setText("Año");

        AnoDef.setText("2012");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel8.setText("Mes");

        MesDef.setText("12");
        MesDef.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MesDefActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel9.setText("Dia");

        DiaDef.setText("21");

        panelCargo.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel10.setText("Año");

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel11.setText("Mes");

        AnoIni.setText("2004");

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel12.setText("Fecha de inicio:");

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel13.setText("Fecha de fin:");

        jLabel14.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel14.setText("Dia");

        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel15.setText("Dia");

        MesIni.setText("04");
        MesIni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MesIniActionPerformed(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel16.setText("Mes");

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel17.setText("Año");

        textCargo.setText("Gobernador");

        AnoFin.setText("2008");

        MesFin.setText("05");

        DiaIni.setText("23");

        DiaFin.setText("02");

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel18.setText("Cargo");

        jLabel21.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel21.setText("Descripcion del cargo:");

        textDescCargo.setColumns(20);
        textDescCargo.setRows(5);
        textDescCargo.setText("Gobernador del Estado \nde California.");
        jScrollPane1.setViewportView(textDescCargo);

        botonCargo.setText("Añadir Cargo");
        botonCargo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCargoActionPerformed(evt);
            }
        });

        panelFicheros.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        labelTitulo5.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo5.setText("Formato:");

        textFormato.setText("pdf");
        textFormato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFormatoActionPerformed(evt);
            }
        });

        labelTitulo6.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo6.setText("URI Fichero");

        textURIFich.setText("/docPolitica/");
        textURIFich.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textURIFichActionPerformed(evt);
            }
        });

        botonAddFich.setText("Añadir");
        botonAddFich.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAddFichActionPerformed(evt);
            }
        });

        labelTitulo7.setFont(new java.awt.Font("Tahoma", 0, 12));
        labelTitulo7.setText("Nombre:");

        textNomFich.setText("gobernadores");
        textNomFich.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textNomFichActionPerformed(evt);
            }
        });

        tablaFicheros.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Ficheros"
            }
        ));
        tablaFicheros.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaFicherosMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(tablaFicheros);

        jButton12.setText("Desligar");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jButton13.setText("Eliminar");
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelFicherosLayout = new javax.swing.GroupLayout(panelFicheros);
        panelFicheros.setLayout(panelFicherosLayout);
        panelFicherosLayout.setHorizontalGroup(
            panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFicherosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFicherosLayout.createSequentialGroup()
                        .addComponent(labelTitulo7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textNomFich, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE))
                    .addGroup(panelFicherosLayout.createSequentialGroup()
                        .addComponent(labelTitulo5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textFormato, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE))
                    .addComponent(labelTitulo6)
                    .addComponent(textURIFich, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                    .addGroup(panelFicherosLayout.createSequentialGroup()
                        .addComponent(jButton12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(botonAddFich, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
                .addContainerGap())
        );
        panelFicherosLayout.setVerticalGroup(
            panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFicherosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panelFicherosLayout.createSequentialGroup()
                        .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelTitulo7)
                            .addComponent(textNomFich, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelTitulo5)
                            .addComponent(textFormato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelTitulo6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textURIFich, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5))
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFicherosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton12)
                        .addComponent(jButton13))
                    .addComponent(botonAddFich))
                .addContainerGap())
        );

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel19.setText("Ficheros del cargo:");

        jButton8.setText("Desligar");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton10.setText("Eliminar");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton9.setText("Cambiar...");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton14.setText("Cambiar...");
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jButton15.setText("Cambiar...");
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelCargoLayout = new javax.swing.GroupLayout(panelCargo);
        panelCargo.setLayout(panelCargoLayout);
        panelCargoLayout.setHorizontalGroup(
            panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCargoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelCargoLayout.createSequentialGroup()
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(textCargo, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE))
                    .addGroup(panelCargoLayout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 100, Short.MAX_VALUE)
                        .addComponent(jButton9))
                    .addGroup(panelCargoLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(AnoIni, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(MesIni, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DiaIni, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelCargoLayout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 113, Short.MAX_VALUE)
                        .addComponent(jButton14))
                    .addGroup(panelCargoLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(AnoFin, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(MesFin, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DiaFin, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel19)
                    .addComponent(panelFicheros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelCargoLayout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                        .addComponent(jButton15))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                    .addGroup(panelCargoLayout.createSequentialGroup()
                        .addComponent(jButton8)
                        .addGap(4, 4, 4)
                        .addComponent(jButton10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonCargo, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelCargoLayout.setVerticalGroup(
            panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCargoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(textCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(AnoIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16)
                    .addComponent(MesIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(DiaIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(AnoFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(MesFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(DiaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelFicheros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonCargo)
                    .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton10))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel22.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel22.setText("Alias:");

        textAlias.setText("Goberneitor");

        botonAlias.setText("Añadir Alias");
        botonAlias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAliasActionPerformed(evt);
            }
        });

        jButton6.setText("Eliminar Alias");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel22)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jButton6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                                .addComponent(botonAlias))
                            .addComponent(textAlias, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textAlias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonAlias)
                    .addComponent(jButton6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        botonAceptar.setText("Aceptar");
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        tablaAlias.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Alias"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaAlias.setColumnSelectionAllowed(true);
        tablaAlias.setFocusable(false);
        tablaAlias.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaAliasMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tablaAlias);
        tablaAlias.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tablaAlias.getColumnModel().getColumn(0).setResizable(false);

        jLabel23.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel23.setText("Lugar de nacimiento:");

        textoLugarNac.setText("Austria");

        jLabel24.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel24.setText("Lugar de muerte:");

        textoLugarDef.setText("Yemen");

        jLabel25.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel25.setText("Biografía:");

        textBiografia.setColumns(20);
        textBiografia.setRows(5);
        textBiografia.setText("Actor de películas de acción\nculturista y gobernador del\nestado de California");
        jScrollPane3.setViewportView(textBiografia);

        tablaCargos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cargos"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tablaCargos.setColumnSelectionAllowed(true);
        tablaCargos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablaCargosMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(tablaCargos);
        tablaCargos.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tablaCargos.getColumnModel().getColumn(0).setResizable(false);
        tablaCargos.getColumnModel().getColumn(0).setHeaderValue("Cargos");

        jLabel26.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel26.setText("Cargos:");

        jButton1.setText("Cambiar...");
        jButton1.setName("cambiaNom"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Cambiar...");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Cambiar...");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Cambiar...");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Cambiar...");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton7.setText("Cambiar...");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton11.setText("Eliminar");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                                .addComponent(jButton1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                                .addComponent(jButton2))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(AnoNac, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(MesNac, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(DiaNac, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                                .addComponent(jButton3))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(AnoDef, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(MesDef, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(DiaDef, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel23)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                                .addComponent(jButton4))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel24)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
                                .addComponent(jButton5))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))
                            .addComponent(textoNomYApe, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(textoLugarNac, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                            .addComponent(textoLugarDef, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(panelCargo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel25)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 159, Short.MAX_VALUE)
                                .addComponent(jButton7))
                            .addComponent(jLabel26)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 337, Short.MAX_VALUE)
                        .addComponent(botonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textoNomYApe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(AnoNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(MesNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(DiaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(AnoDef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addComponent(MesDef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9)
                            .addComponent(DiaDef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel23)
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textoLugarNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel24)
                            .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textoLugarDef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane2, 0, 0, Short.MAX_VALUE)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 617, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel25)
                            .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                        .addComponent(jLabel26)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(panelCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonAceptar)
                    .addComponent(jButton11))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void MesIniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MesIniActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_MesIniActionPerformed

    private void MesDefActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MesDefActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_MesDefActionPerformed

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        if (estado == estados.MODIFICAR) {
            if(manejador.getId()!=null)
                manejador.cambiaEstado(estados.VENTANA3);
            else
                manejador.cambiaEstado(estados.MODIFICAR);
        } else if (estado == estados.CREAR) {
            if (camposRellenos()) {
                try {
                    // Creamos el Personaje
                    manejador.getBBDDManager().consultaInsetar("INSERT INTO personaje "
                            + "(nombreYApe,fechaNac,lugarNac,fechaMuerte,lugarMuerte,biografia) VALUES"
                            + "('" + textoNomYApe.getText() + "',"
                            + "'" + AnoNac.getText() + "-" + MesNac.getText() + "-" + DiaNac.getText() + "'"
                            + ",'" + textoLugarNac.getText() + "',"
                            + "'" + AnoDef.getText() + "-" + MesDef.getText() + "-" + DiaDef.getText() + "',"
                            + "'" + textoLugarDef.getText() + "',"
                            + "'" + textBiografia.getText() + "');");
                    // Asociamos el Personaje al Documento
                    
                    int idDocumento = Integer.parseInt(manejador.getBBDDManager().consultaPeticion(
                            "SELECT max(id) as id FROM documento;", "id"));
                    if(manejador.getId()!=null)
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO "
                            + "personajesDocumento (idDocumento,personaje) VALUES"
                            + "(" + (int)Integer.valueOf(manejador.getId()) + ",'" + textoNomYApe.getText() + "');");
                    else
                    manejador.getBBDDManager().consultaInsetar("INSERT INTO "
                            + "personajesDocumento (idDocumento,personaje) VALUES"
                            + "(" + idDocumento + ",'" + textoNomYApe.getText() + "');");
                    // Añadimos sus alias
                    Iterator<String> itAlias = alias.iterator();
                    while (itAlias.hasNext()) {
                        String a = itAlias.next();
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO alias "
                                + "(personaje,nomAlias) VALUES('" + textoNomYApe.getText() + "',"
                                + "'" + a + "');");
                    }
                    // Borramos informacion de la memoria
                    alias.clear();
                    actualizaTablaAlias();
                    // Añadimos sus cargos
                    Iterator<DescriptorCargo> itCargo = cargos.iterator();
                    while (itCargo.hasNext()) {
                        DescriptorCargo cargo = (DescriptorCargo) itCargo.next();
                        // Creamos el cargo en la BBDD, si ya existe no se introducirá
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO "
                                + "cargo(nombreCargo) VALUES('" + cargo.getCargo() + "');");
                        // Creamos y asociamos los ficheros al cargo
                        Iterator<DescriptorFichero> it = cargo.getFichero().iterator();
                        while (it.hasNext()) {
                            // Creamos el fichero
                            DescriptorFichero f = (DescriptorFichero) it.next();
                            manejador.getBBDDManager().creaFicheroCargo(f.getNombre(),
                                    f.getFormato(), f.getURI());
                            // Asociamos el fichero al cargo
                            manejador.getBBDDManager().consultaInsetar("INSERT INTO "
                                    + "cargosFichero(cargo,ficheroCargo) VALUES "
                                    + "('" + cargo.getCargo() + "','" + f.getNombre() + "');");
                        }
                        // Asociamos el cargo al personaje
                        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO "
                                + "desempenia(personaje, cargo, descCargo, FechaIni, FechaFin) VALUES"
                                + "('" + textoNomYApe.getText() + "',"
                                + "'" + cargo.getCargo() + "',"
                                + "'" + cargo.getDescCargo() + "',"
                                + "'" + sdf.format(cargo.getFechaIni()) + "',"
                                + "'" + sdf.format(cargo.getFechaFin()) + "');");
                    }
                    // Borramos informacion de la memoria
                    cargos.clear();
                    actualizaTablaCargos();
                    if(manejador.getId()!=null)
                        manejador.getV1().setEstado(estados.MODIFICAR);
                    manejador.cambiaEstado(estados.VENTANA3);
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null, ex, "Aviso", 2);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Debes rellenar todos los campos", "Aviso", 2);
            }
        } else if (estado == estados.CONSULTAR) {
            manejador.cambiaEstado(estados.VENTANA1);
        }
    }//GEN-LAST:event_botonAceptarActionPerformed

    private void botonAliasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAliasActionPerformed
        if (estado == estados.MODIFICAR) {
            try {
                manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`alias` (`personaje`, `nomAlias`) VALUES ('" + personaje.getNombreYApe() + "', '" + textAlias.getText() + "');");
                cargaTablaAlias(personaje.getNombreYApe());
            } catch (SQLException ex) {
                Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (estado == estados.CREAR) {
            if (!alias.contains(textAlias.getText())) {
                alias.add(textAlias.getText());
            }
            textAlias.setText("");
            actualizaTablaAlias();
        }
    }//GEN-LAST:event_botonAliasActionPerformed

    private void botonCargoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCargoActionPerformed
        // Añadimos el cargo a la lista de cargos
        if (estado == estados.MODIFICAR) {
            try {
                if (datosCargoLleno()) {
                    String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM `dochistoria`.`cargo` WHERE `cargo`.`nombreCargo`='" + textCargo.getText() + "';", "nombreCargo");
                    if (consulta == null) {
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`cargo` (`nombreCargo`) VALUES ('" + textCargo.getText() + "');");
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`desempenia` (`personaje`,`cargo`,`descCargo`,`FechaIni`,`FechaFin`) VALUES ('" + personaje.getNombreYApe() + "','" + textCargo.getText() + "','" + textDescCargo.getText() + "','" + AnoIni.getText() + "-" + MesIni.getText() + "-" + DiaIni.getText() + "','" + AnoFin.getText() + "-" + MesFin.getText() + "-" + DiaFin.getText() + "');");
                    } else {
                        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM desempenia WHERE `desempenia`.`personaje`='" + personaje.getNombreYApe() + "' AND `desempenia`.`cargo`='" + textCargo.getText() + "';", "personaje");
                        if (consulta == null) {
                            manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`desempenia` (`personaje`,`cargo`,`descCargo`,`FechaIni`,`FechaFin`) VALUES ('" + personaje.getNombreYApe() + "','" + textCargo.getText() + "','" + textDescCargo.getText() + "','" + AnoIni.getText() + "-" + MesIni.getText() + "-" + DiaIni.getText() + "','" + AnoFin.getText() + "-" + MesFin.getText() + "-" + DiaFin.getText() + "');");
                        } else {
                            JOptionPane.showMessageDialog(null, "Este personaje ya tiene asociado el cargo " + textCargo.getText() + ". Solo puede modificarlo, desligarlo o eliminarlo.", "Aviso", 2);
                        }
                    }
                } else if (estado == estados.CREAR) {
                    JOptionPane.showMessageDialog(null, "Debe rellenar todos los campos pertinentes para introducir un nuevo cargo al personaje.", "Aviso", 2);
                }
                //manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`cargo` (`nombreCargo`) VALUES ('"+textCargo.getText()+"');");
                //manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`desempenia` (`personaje`,`cargo`,`descCargo`,`FechaIni`,`FechaFin`) VALUES ('"+personaje.getNombreYApe()+"','"+textCargo.getText()+"','"+textDescCargo.getText()+"','"+AnoIni.getText()+"-"+MesIni.getText()+"-"+DiaIni.getText()+"','"+AnoFin.getText()+"-"+MesFin.getText()+"-"+DiaFin.getText()+"');");
                cargaTablaCargos(personaje.getNombreYApe());
                cargaTablaCargosFichero(textCargo.getText());
            } catch (SQLException ex) {
                Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            DescriptorCargo cargo = new DescriptorCargo(textCargo.getText(),
                    textDescCargo.getText(),
                    java.sql.Date.valueOf(AnoIni.getText() + "-" + MesIni.getText() + "-" + DiaIni.getText()),
                    java.sql.Date.valueOf(AnoFin.getText() + "-" + MesFin.getText() + "-" + DiaFin.getText()),
                    fichCargo);
            if (!cargos.contains(cargo)) {
                cargos.add(cargo);
                textCargo.setText("");
                textDescCargo.setText("");
                AnoIni.setText("");
                AnoFin.setText("");
                MesIni.setText("");
                MesFin.setText("");
                DiaIni.setText("");
                DiaFin.setText("");
                textAlias.setText("");
                textNomFich.setText("");
                textURIFich.setText("");
                textFormato.setText("");
                actualizaTablaCargos();
                fichCargo.clear();
                actualizaTablaFicheros();
            }
        }
    }//GEN-LAST:event_botonCargoActionPerformed

    private void textFormatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFormatoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_textFormatoActionPerformed

    private void textURIFichActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textURIFichActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_textURIFichActionPerformed

    private void botonAddFichActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAddFichActionPerformed
        if (estado == estados.MODIFICAR) {
            try {
                String consulta;
                consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM cargo WHERE `cargo`.`nombreCargo`='" + textCargo.getText() + "';", "nombreCargo");
                if (consulta != null) {
                    consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM fichero_cargo WHERE `fichero_cargo`.`nombreFichCargo`='" + textNomFich.getText() + "';", "nombreFichCargo");
                    if (consulta == null) {
                        if (textNomFich.getText().length() > 0 && textFormato.getText().length() > 0 && textURIFich.getText().length() > 0) {
                            manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`fichero_cargo` (`nombreFichCargo`,`formatoFichCargo`,`uriFichCargo`) VALUES ('" + textNomFich.getText() + "','" + textFormato.getText() + "','" + textURIFich.getText() + "');");
                            manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`cargosfichero` (`cargo`,`ficheroCargo`) VALUES ('" + textCargo.getText() + "','" + textNomFich.getText() + "');");
                        } else {
                            JOptionPane.showMessageDialog(null, "Si el fichero no existe en la base de datos, se deben rellenar todos los campos.", "Aviso", 2);
                        }
                    } else {
                        manejador.getBBDDManager().consultaInsetar("INSERT INTO `dochistoria`.`cargosfichero` (`cargo`,`ficheroCargo`) VALUES ('" + textCargo.getText() + "','" + textNomFich.getText() + "');");
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "No se pueden añadir ficheros a un cargo que no se ha creado.", "Aviso", 2);
                }
                cargaTablaCargosFichero(textCargo.getText());
            } catch (SQLException ex) {
                Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (estado == estados.CREAR) {
            DescriptorFichero f = new DescriptorFichero(textNomFich.getText(),
                    textFormato.getText(),
                    textURIFich.getText());
            if (textNomFich.getText().length() > 0 && textFormato.getText().length() > 0
                    && textURIFich.getText().length() > 0) {
                if (!fichCargo.contains(f)) {
                    fichCargo.add(f);
                }
                textNomFich.setText("");
                textFormato.setText("");
                textURIFich.setText("");
                actualizaTablaFicheros();
            } else {
                JOptionPane.showMessageDialog(null, "Debes rellenar todos los campos del fichero del cargo", "Aviso", 2);
            }
        }
}//GEN-LAST:event_botonAddFichActionPerformed

    private void textNomFichActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textNomFichActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_textNomFichActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    try {
        if(textoNomYApe.getText().length()>0){
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`personaje` SET `nombreYApe` = '" + textoNomYApe.getText() + "' WHERE `personaje`.`nombreYApe` = '" + personaje.getNombreYApe() + "';");
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`alias` SET `personaje` = '" + textoNomYApe.getText() + "' WHERE `alias`.`personaje` = '" + personaje.getNombreYApe() + "';");
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`desempenia` SET `personaje` = '" + textoNomYApe.getText() + "' WHERE `desempenia`.`personaje` = '" + personaje.getNombreYApe() + "';");
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`personajesdocumento` SET `personaje` = '" + textoNomYApe.getText() + "' WHERE `personajesdocumento`.`personaje` = '" + personaje.getNombreYApe() + "';");

        rellenaPersonaje(personaje);
        } else {
            JOptionPane.showMessageDialog(null, "No puede modificarse si el campo está en blanco.", "Aviso", 2);
            textoNomYApe.setText(personaje.getNombreYApe());
        }
        // TODO add your handling code here:
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`personaje` SET `fechaNac` = '" + AnoNac.getText() + "-" + MesNac.getText() + "-" + DiaNac.getText() + "' WHERE `personaje`.`nombreYApe` = '" + personaje.getNombreYApe() + "';");
        //rellenaPersonaje(personaje);
        // TODO add your handling code here:
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`personaje` SET `fechaMuerte` = '" + AnoDef.getText() + "-" + MesDef.getText() + "-" + DiaDef.getText() + "' WHERE `personaje`.`nombreYApe` = '" + personaje.getNombreYApe() + "';");
        //rellenaPersonaje(personaje);
        // TODO add your handling code here:
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`personaje` SET `lugarNac` = '" + textoLugarNac.getText() + "' WHERE `personaje`.`nombreYApe` = '" + personaje.getNombreYApe() + "';");
        //rellenaPersonaje(personaje);
        // TODO add your handling code here:
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`personaje` SET `lugarMuerte` = '" + textoLugarDef.getText() + "' WHERE `personaje`.`nombreYApe` = '" + personaje.getNombreYApe() + "';");
        //rellenaPersonaje(personaje);
        // TODO add your handling code here:
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`personaje` SET `biografia` = '" + textBiografia.getText() + "' WHERE `personaje`.`nombreYApe` = '" + personaje.getNombreYApe() + "';");
        //rellenaPersonaje(personaje);
        // TODO add your handling code here:
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton7ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`alias` WHERE `alias`.`personaje`='" + personaje.getNombreYApe() + "' AND `alias`.`nomAlias`='" + textAlias.getText() + "';");
        cargaTablaAlias(personaje.getNombreYApe());
        //rellenaPersonaje(personaje);
        // TODO add your handling code here:
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton6ActionPerformed

private void tablaCargosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaCargosMouseClicked
// TODO add your handling code here:
    String cargo = tablaCargos.getValueAt(tablaCargos.getSelectedRow(), 0).toString();
    rellenaDatosCargo(cargo);

}//GEN-LAST:event_tablaCargosMouseClicked

    private void rellenaDatosCargo(String cargo) {
        textCargo.setText(cargo);
        textFormato.setText("");
        textNomFich.setText("");
        textURIFich.setText("");
        String consulta;
        try {
            consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM desempenia WHERE `desempenia`.`personaje`='" + personaje.getNombreYApe() + "' AND `desempenia`.`cargo`='" + cargo + "';", "descCargo");
            textDescCargo.setText(consulta);
            consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM desempenia WHERE `desempenia`.`personaje`='" + personaje.getNombreYApe() + "' AND `desempenia`.`cargo`='" + cargo + "';", "FechaIni");
            String[] fecha = consulta.split("-");
            AnoIni.setText(fecha[0]);
            MesIni.setText(fecha[1]);
            DiaIni.setText(fecha[2]);
            consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM desempenia WHERE `desempenia`.`personaje`='" + personaje.getNombreYApe() + "' AND `desempenia`.`cargo`='" + cargo + "';", "FechaFin");
            fecha = consulta.split("-");
            AnoFin.setText(fecha[0]);
            MesFin.setText(fecha[1]);
            DiaFin.setText(fecha[2]);
            cargaTablaCargosFichero(cargo);

        } catch (SQLException ex) {
            Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

private void tablaAliasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaAliasMouseClicked
// TODO add your handling code here:
    textAlias.setText(tablaAlias.getValueAt(tablaAlias.getSelectedRow(), 0).toString());
}//GEN-LAST:event_tablaAliasMouseClicked

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
    // TODO add your handling code here:    
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`desempenia` WHERE `desempenia`.`personaje`='" + personaje.getNombreYApe() + "' AND `desempenia`.`cargo`='" + textCargo.getText() + "';");
        cargaTablaCargos(personaje.getNombreYApe());
        vaciaDatosFichero();
        vaciaDatosCargo();
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton8ActionPerformed

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`cargo` WHERE `cargo`.`nombreCargo`='" + textCargo.getText() + "';");
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM desempenia WHERE `desempenia`.`cargo`='" + textCargo.getText() + "'", "personaje");
        if (consulta != null) {
            String[] consultas = consulta.split(",");
            for (int k = 0; k < consultas.length; k++) {
                manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`desempenia` WHERE `desempenia`.`personaje`='" + consultas[k] + "' AND `desempenia`.`cargo`='" + textCargo.getText() + "';");
            }
        }
        vaciaDatosFichero();
        vaciaDatosCargo();
        cargaTablaCargos(personaje.getNombreYApe());
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton10ActionPerformed

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
    try {
        if(manejador.getId()!=null){
            manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`personajesdocumento` WHERE `personajesdocumento`.`idDocumento`="+(int)Integer.valueOf(manejador.getId())+" AND `personajesdocumento`.`personaje`='"+ personaje.getNombreYApe() + "';");
            manejador.cambiaEstado(estados.VENTANA3);
        }else{
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`personaje` WHERE `personaje`.`nombreYApe`='" + personaje.getNombreYApe() + "';");
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`alias` WHERE `alias`.`personaje`='" + personaje.getNombreYApe() + "';");
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`desempenia` WHERE `desempenia`.`personaje`='" + personaje.getNombreYApe() + "';");
        manejador.cambiaEstado(estados.MODIFICAR);
        }
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton11ActionPerformed

private void tablaFicherosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaFicherosMouseClicked
// TODO add your handling code here:
    String fichero = tablaFicheros.getValueAt(tablaFicheros.getSelectedRow(), 0).toString();
    try {
        rellenaDatosFichero(fichero);
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_tablaFicherosMouseClicked

private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
    // TODO add your handling code here:    
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`cargosfichero` WHERE `cargosfichero`.`cargo`='" + textCargo.getText() + "' AND `cargosfichero`.`ficheroCargo`='" + textNomFich.getText() + "';");
        cargaTablaCargosFichero(textCargo.getText());
        vaciaDatosFichero();
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton12ActionPerformed

private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
// TODO add your handling code here:
    try {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`fichero_cargo` WHERE `fichero_cargo`.`nombreFichCargo`='" + textNomFich.getText() + "';");
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`cargosfichero` WHERE `cargosfichero`.`ficheroCargo`='" + textNomFich.getText() + "';");
        /*String consulta=manejador.getBBDDManager().consultaPeticion("SELECT * FROM cargosfichero WHERE `cargosfichero`.`ficheroCargo`='"+textNomFich.getText()+"'","cargo");
        if(consulta!=null){
        String[] consultas=consulta.split(",");
        for (int k = 0; k < consultas.length; k++) {
        manejador.getBBDDManager().consultaInsetar("DELETE FROM `dochistoria`.`desempenia` WHERE `desempenia`.`personaje`='"+consultas[k]+"' AND `desempenia`.`cargo`='"+textCargo.getText()+"';");
        }
        }*/
        cargaTablaCargosFichero(textCargo.getText());
        vaciaDatosFichero();
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton13ActionPerformed

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
    // TODO add your handling code here:    
    try {
        String consulta;
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM cargo WHERE `cargo`.`nombreCargo`='" + textCargo.getText() + "';", "nombreCargo");
        if (consulta != null) {
            String fecha = AnoIni.getText() + "-" + MesIni.getText() + "-" + DiaIni.getText();
            manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`desempenia` SET `FechaIni` = '" + fecha + "' WHERE `desempenia`.`personaje` = '" + personaje.getNombreYApe() + "' AND `desempenia`.`cargo`= '" + textCargo.getText() + "';");
        } else {
            JOptionPane.showMessageDialog(null, "No se pueden modificar datos de un cargo inexistente.", "Aviso", 2);
        }
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton9ActionPerformed

private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
// TODO add your handling code here:
    try {
        String consulta;
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM cargo WHERE `cargo`.`nombreCargo`='" + textCargo.getText() + "';", "nombreCargo");
        if (consulta != null) {
            String fecha = AnoFin.getText() + "-" + MesFin.getText() + "-" + DiaFin.getText();
            manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`desempenia` SET `FechaFin` = '" + fecha + "' WHERE `desempenia`.`personaje` = '" + personaje.getNombreYApe() + "' AND `desempenia`.`cargo`= '" + textCargo.getText() + "';");
        } else {
            JOptionPane.showMessageDialog(null, "No se pueden modificar datos de un cargo inexistente.", "Aviso", 2);
        }
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton14ActionPerformed

private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
// TODO add your handling code here:
    try {
        String consulta;
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM cargo WHERE `cargo`.`nombreCargo`='" + textCargo.getText() + "';", "nombreCargo");
        if (consulta != null) {
            manejador.getBBDDManager().consultaInsetar("UPDATE `dochistoria`.`desempenia` SET `descCargo` = '" + textDescCargo.getText() + "' WHERE `desempenia`.`personaje` = '" + personaje.getNombreYApe() + "' AND `desempenia`.`cargo`= '" + textCargo.getText() + "';");
        } else {
            JOptionPane.showMessageDialog(null, "No se pueden modificar datos de un cargo inexistente.", "Aviso", 2);
        }
    } catch (SQLException ex) {
        Logger.getLogger(VentanaCrearPj.class.getName()).log(Level.SEVERE, null, ex);
    }
}//GEN-LAST:event_jButton15ActionPerformed

    private void rellenaDatosFichero(String fichero) throws SQLException {
        textNomFich.setText(fichero);
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM `dochistoria`.`fichero_cargo` WHERE `fichero_cargo`.`nombreFichCargo`='" + fichero + "';", "formatoFichCargo");
        textFormato.setText(consulta);
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM `dochistoria`.`fichero_cargo` WHERE `fichero_cargo`.`nombreFichCargo`='" + fichero + "';", "uriFichCargo");
        textURIFich.setText(consulta);
    }

    private void actualizaTablaCargos() {
        DefaultTableModel m;
        m = new DefaultTableModel(new Object[]{"Cargos"}, 0);
        Iterator<DescriptorCargo> itCargos = cargos.iterator();
        while (itCargos.hasNext()) {
            DescriptorCargo cargo = itCargos.next();
            m.addRow(new Object[]{cargo.getCargo()});
        }
        tablaCargos.setModel(m);
    }

    private void actualizaTablaAlias() {
        DefaultTableModel m;
        m = new DefaultTableModel(new Object[]{"Alias"}, 0);
        Iterator<String> itAlias = alias.iterator();
        while (itAlias.hasNext()) {
            String als = itAlias.next();
            m.addRow(new Object[]{als});
        }
        tablaAlias.setModel(m);
    }

    private void actualizaTablaFicheros() {
        DefaultTableModel m;
        m = new DefaultTableModel(new Object[]{"Ficheros"}, 0);
        Iterator<DescriptorFichero> it = fichCargo.iterator();
        while (it.hasNext()) {
            DescriptorFichero fich = (DescriptorFichero) it.next();
            m.addRow(new Object[]{fich.getNombre()});
        }
        tablaFicheros.setModel(m);
    }

    private void vaciaDatosFichero() {
        textNomFich.setText("");
        textFormato.setText("");
        textURIFich.setText("");
    }

    private void vaciaDatosCargo() {
        textCargo.setText("");
        AnoIni.setText("");
        MesIni.setText("");
        DiaIni.setText("");
        AnoFin.setText("");
        MesFin.setText("");
        DiaFin.setText("");
        textDescCargo.setText("");
    }

    ;

    private boolean datosCargoLleno() {
        return textCargo.getText().length() > 0
                && AnoIni.getText().length() > 0
                && MesIni.getText().length() > 0
                && DiaIni.getText().length() > 0
                && AnoFin.getText().length() > 0
                && MesFin.getText().length() > 0
                && DiaFin.getText().length() > 0
                && textDescCargo.getText().length() > 0;
    }

    private void rellenaPersonaje(DescriptorPersonaje personaje) {
        personaje.setNombreYApe(textoNomYApe.getText());
        personaje.setLugarNacimiento(textoLugarNac.getText());
        personaje.setBiografia(textBiografia.getText());
        personaje.setFechaNac(java.sql.Date.valueOf(AnoNac.getText() + "-"
                + MesNac.getText() + "-" + DiaNac.getText()));
        personaje.setFechaMuerte(java.sql.Date.valueOf(AnoDef.getText()
                + "-" + MesDef.getText() + "-" + DiaDef.getText()));
    }

    private boolean camposRellenos() {
        return (textBiografia.getText().length() > 0
                && textoLugarNac.getText().length() > 0
                && textoLugarDef.getText().length() > 0
                && textoNomYApe.getText().length() > 0
                && AnoNac.getText().length() > 0
                && DiaNac.getText().length() > 0
                && MesNac.getText().length() > 0
                && AnoDef.getText().length() > 0
                && DiaDef.getText().length() > 0
                && MesDef.getText().length() > 0
                && !cargos.isEmpty()
                && !alias.isEmpty());
    }

    public void cargaPersonaje(String personaje) throws SQLException {
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM personaje WHERE `personaje`.`nombreYApe` = '" + personaje + "'", "biografia");
        textBiografia.setText(consulta);
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM personaje WHERE `personaje`.`nombreYApe` = '" + personaje + "'", "lugarNac");
        textoLugarNac.setText(consulta);
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM personaje WHERE `personaje`.`nombreYApe` = '" + personaje + "'", "lugarMuerte");
        textoLugarDef.setText(consulta);
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM personaje WHERE `personaje`.`nombreYApe` = '" + personaje + "'", "nombreYApe");
        textoNomYApe.setText(consulta);
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM personaje WHERE `personaje`.`nombreYApe` = '" + personaje + "'", "fechaNac");
        String[] fecha = consulta.split("-");
        AnoNac.setText(fecha[0]);
        MesNac.setText(fecha[1]);
        DiaNac.setText(fecha[2]);
        consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM personaje WHERE `personaje`.`nombreYApe` = '" + personaje + "'", "fechaMuerte");
        fecha = consulta.split("-");
        AnoDef.setText(fecha[0]);
        MesDef.setText(fecha[1]);
        DiaDef.setText(fecha[2]);

        cargaTablaAlias(personaje);

        cargaTablaCargos(personaje);

        rellenaPersonaje(this.personaje);
    }

    void cargaTablaAlias(String personaje) throws SQLException {
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM alias WHERE `alias`.`personaje` = '" + personaje + "'", "nomAlias");
        tablaAlias.removeAll();
        if (consulta != null) {
            DefaultTableModel m;
            m = new DefaultTableModel(new Object[]{"Alias"}, 0);
            String[] als = consulta.split(",");
            System.out.println(als);

            for (int k = 0; k < als.length; k++) {
                m.addRow(new Object[]{als[k]});
            }
            tablaAlias.setModel(m);
        } else {
            DefaultTableModel m = new DefaultTableModel(new Object[]{"Alias"}, 0);
            tablaAlias.setModel(m);
        }
    }

    ;

    void cargaTablaCargos(String personaje) throws SQLException {
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM desempenia WHERE `desempenia`.`personaje` = '" + personaje + "'", "cargo");
        tablaCargos.removeAll();
        if (consulta != null) {
            DefaultTableModel m;
            m = new DefaultTableModel(new Object[]{"Cargos"}, 0);
            String[] cargs = consulta.split(",");
            System.out.println(cargs);

            for (int k = 0; k < cargs.length; k++) {
                m.addRow(new Object[]{cargs[k]});
            }
            tablaCargos.setModel(m);
        } else {
            DefaultTableModel m = new DefaultTableModel(new Object[]{"Cargos"}, 0);
            tablaCargos.setModel(m);
        }
    }

    ;

    void cargaTablaCargosFichero(String cargo) throws SQLException {
        String consulta = manejador.getBBDDManager().consultaPeticion("SELECT * FROM cargosfichero WHERE `cargosfichero`.`cargo`='" + cargo + "';", "ficheroCargo");
        tablaFicheros.removeAll();
        if (consulta != null) {
            DefaultTableModel m;
            m = new DefaultTableModel(new Object[]{"Ficheros"}, 0);
            String[] ficheros = consulta.split(",");
            System.out.println(ficheros);

            for (int k = 0; k < ficheros.length; k++) {
                m.addRow(new Object[]{ficheros[k]});
            }
            tablaFicheros.setModel(m);
        } else {
            DefaultTableModel m = new DefaultTableModel(new Object[]{"Ficheros"}, 0);
            tablaFicheros.setModel(m);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new VentanaCrearPj(new GUIManager()).setVisible(true);
                } catch (SQLException ex) {
                    System.out.println(ex.toString());
                }
            }
        });
    }

    void mandaEstadoV1(estados s) {
        estado = s;
        textAlias.setEditable(true);
        textBiografia.setEditable(true);
        textCargo.setEditable(true);
        textDescCargo.setEditable(true);
        textFormato.setEditable(true);
        textNomFich.setEditable(true);
        textURIFich.setEditable(true);
        textoLugarDef.setEditable(true);
        textoLugarNac.setEditable(true);
        textoNomYApe.setEditable(true);
        AnoIni.setEditable(true);
        MesIni.setEditable(true);
        DiaIni.setEditable(true);
        AnoFin.setEditable(true);
        MesFin.setEditable(true);
        DiaFin.setEditable(true);
        AnoNac.setEditable(true);
        MesNac.setEditable(true);
        DiaNac.setEditable(true);
        AnoDef.setEditable(true);
        MesDef.setEditable(true);
        DiaDef.setEditable(true);
        if (s == estados.CREAR) {
            jButton1.setVisible(false);
            jButton2.setVisible(false);
            jButton3.setVisible(false);
            jButton4.setVisible(false);
            jButton5.setVisible(false);
            jButton6.setVisible(false);
            jButton7.setVisible(false);
            jButton8.setVisible(false);
            jButton9.setVisible(false);
            jButton9.setVisible(false);
            jButton10.setVisible(false);
            jButton11.setVisible(false);
            jButton12.setVisible(false);
            jButton13.setVisible(false);
            jButton14.setVisible(false);
            jButton15.setVisible(false);
        } else if (s == estados.MODIFICAR) {
            jButton1.setVisible(true);
            jButton2.setVisible(true);
            jButton3.setVisible(true);
            jButton4.setVisible(true);
            jButton5.setVisible(true);
            jButton6.setVisible(true);
            jButton7.setVisible(true);
            jButton8.setVisible(true);
            jButton9.setVisible(true);
            jButton10.setVisible(true);
            jButton11.setVisible(true);
            if(manejador.getId()==null)
                jButton11.setText("Eliminar");
            else
                jButton11.setText("Desligar");
            jButton12.setVisible(true);
            jButton13.setVisible(true);
            jButton14.setVisible(true);
            jButton15.setVisible(true);
            vaciaDatosFichero();
            vaciaDatosCargo();
        } else if (s == estados.CONSULTAR) {
            textAlias.setText("");
            textAlias.setEditable(false);
            textBiografia.setEditable(false);
            textCargo.setEditable(false);
            textDescCargo.setEditable(false);
            textFormato.setEditable(false);
            textNomFich.setEditable(false);
            textURIFich.setEditable(false);
            textoLugarDef.setEditable(false);
            textoLugarNac.setEditable(false);
            textoNomYApe.setEditable(false);
            jButton1.setVisible(false);
            jButton2.setVisible(false);
            jButton3.setVisible(false);
            jButton4.setVisible(false);
            jButton5.setVisible(false);
            jButton6.setVisible(false);
            jButton7.setVisible(false);
            jButton8.setVisible(false);
            jButton9.setVisible(false);
            jButton10.setVisible(false);
            jButton11.setVisible(false);
            jButton12.setVisible(false);
            jButton13.setVisible(false);
            jButton14.setVisible(false);
            jButton15.setVisible(false);
            botonAceptar.setText("Terminar");
            botonAddFich.setVisible(false);
            botonAlias.setVisible(false);
            botonCargo.setVisible(false);
            AnoIni.setEditable(false);
            MesIni.setEditable(false);
            DiaIni.setEditable(false);
            AnoFin.setEditable(false);
            MesFin.setEditable(false);
            DiaFin.setEditable(false);
            AnoNac.setEditable(false);
            MesNac.setEditable(false);
            DiaNac.setEditable(false);
            AnoDef.setEditable(false);
            MesDef.setEditable(false);
            DiaDef.setEditable(false);
            vaciaDatosFichero();
            vaciaDatosCargo();
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AnoDef;
    private javax.swing.JTextField AnoFin;
    private javax.swing.JTextField AnoIni;
    private javax.swing.JTextField AnoNac;
    private javax.swing.JTextField DiaDef;
    private javax.swing.JTextField DiaFin;
    private javax.swing.JTextField DiaIni;
    private javax.swing.JTextField DiaNac;
    private javax.swing.JTextField MesDef;
    private javax.swing.JTextField MesFin;
    private javax.swing.JTextField MesIni;
    private javax.swing.JTextField MesNac;
    private javax.swing.JButton botonAceptar;
    private javax.swing.JButton botonAddFich;
    private javax.swing.JButton botonAlias;
    private javax.swing.JButton botonCargo;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel labelTitulo5;
    private javax.swing.JLabel labelTitulo6;
    private javax.swing.JLabel labelTitulo7;
    private javax.swing.JPanel panelCargo;
    private javax.swing.JPanel panelFicheros;
    private javax.swing.JTable tablaAlias;
    private javax.swing.JTable tablaCargos;
    private javax.swing.JTable tablaFicheros;
    private javax.swing.JTextField textAlias;
    private javax.swing.JTextArea textBiografia;
    private javax.swing.JTextField textCargo;
    private javax.swing.JTextArea textDescCargo;
    private javax.swing.JTextField textFormato;
    private javax.swing.JTextField textNomFich;
    private javax.swing.JTextField textURIFich;
    private javax.swing.JTextField textoLugarDef;
    private javax.swing.JTextField textoLugarNac;
    private javax.swing.JTextField textoNomYApe;
    // End of variables declaration//GEN-END:variables
}
